﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class ClickGround : MonoBehaviour
{
    public Vector3 m_destinationPosition;	
	
    void Update()
    {
        Clickground();
		//HideGizmo();
    }
    public void Clickground()// 点击屏幕空白位置则设定目标点
	{
		if (Input.GetMouseButton (0)) 
		{
			//#if IPHONE||ANDROID
			//if (!EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
			//#else
			if (EventSystem.current.IsPointerOverGameObject ())
				//#endif
			{
				//Debug.Log ("Click on the UI");
			}
			else
			{
				Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
				RaycastHit hit;
				//if (Physics.Raycast (ray, out hit, 100.0f, LayerMask.NameToLayer("Ignore Raycast")))
				if (Physics.Raycast (ray, out hit))
				{
					if (hit.transform.tag == "Ground")
					{
						Debug.Log ("Click on the ground");						
						m_destinationPosition = hit.point;
						ShowGizmo();
						//Debug.Log (m_destinationPosition);
						if (DelegateManager.Instance.ClickGround != null)
						{
							DelegateManager.Instance.ClickGround();
						}
					}
				}
			}
		}
	}
	void ShowGizmo()//移动点击图示的位置
	{
		PoolManager.Instance.m_Flag.transform.position=m_destinationPosition;
	}
	void HideGizmo()//隐藏点击图示的位置
	{
		PoolManager.Instance.m_Flag.transform.position=Vector3.zero;
	}
	
}